package com.ruoyi.web.controller.system;

import java.util.HashMap;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysWayoftravel;
import com.ruoyi.system.service.ISysWayoftravelService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 旅游类型Controller
 * 
 * @author ruoyi
 * @date 2020-10-12
 */
@Controller
@RequestMapping("/system/wayoftravel")
public class SysWayoftravelController extends BaseController
{
    private String prefix = "system/wayoftravel";

    @Autowired
    private ISysWayoftravelService sysWayoftravelService;

    @RequiresPermissions("system:wayoftravel:view")
    @GetMapping()
    public String wayoftravel()
    {
        return prefix + "/wayoftravel";
    }

    /**
     * 查询旅游类型列表
     */
    @RequiresPermissions("system:wayoftravel:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysWayoftravel sysWayoftravel)
    {
        startPage();
        List<SysWayoftravel> list = sysWayoftravelService.selectSysWayoftravelList(sysWayoftravel);
        return getDataTable(list);
    }

    /**
     * 导出旅游类型列表
     */
    @RequiresPermissions("system:wayoftravel:export")
    @Log(title = "旅游类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysWayoftravel sysWayoftravel)
    {
        List<SysWayoftravel> list = sysWayoftravelService.selectSysWayoftravelList(sysWayoftravel);
        ExcelUtil<SysWayoftravel> util = new ExcelUtil<SysWayoftravel>(SysWayoftravel.class);
        return util.exportExcel(list, "wayoftravel");
    }

    /**
     * 新增旅游类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存旅游类型
     */
    @RequiresPermissions("system:wayoftravel:add")
    @Log(title = "旅游类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysWayoftravel sysWayoftravel)
    {
        return toAjax(sysWayoftravelService.insertSysWayoftravel(sysWayoftravel));
    }

    /**
     * 修改旅游类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SysWayoftravel sysWayoftravel = sysWayoftravelService.selectSysWayoftravelById(id);
        mmap.put("sysWayoftravel", sysWayoftravel);
        return prefix + "/edit";
    }

    /**
     * 修改保存旅游类型
     */
    @RequiresPermissions("system:wayoftravel:edit")
    @Log(title = "旅游类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysWayoftravel sysWayoftravel)
    {
        return toAjax(sysWayoftravelService.updateSysWayoftravel(sysWayoftravel));
    }

    /**
     * 删除旅游类型
     */
    @RequiresPermissions("system:wayoftravel:remove")
    @Log(title = "旅游类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysWayoftravelService.deleteSysWayoftravelByIds(ids));
    }

    /**
     * 查询性别比例
     */
    @RequiresPermissions("system:wayoftravel:list")
    @GetMapping("/gender")
    @ResponseBody
    public HashMap<String,Double> gender()
    {
        HashMap<String, Double> gender = sysWayoftravelService.gender();
        return gender;
    }

}
